home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / exec / procure.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-13  |  2.5 KB  |  100 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: procure.c,v 1.5 1996/09/13 17:51:23 digulla Exp $
  4.     $Log: procure.c,v $
  5.     Revision 1.5  1996/09/13 17:51:23  digulla
  6.     Use IPTR
  7.  
  8.     Revision 1.4  1996/08/13 13:56:05  digulla
  9.     Replaced __AROS_LA by __AROS_LHA
  10.     Replaced some __AROS_LH*I by __AROS_LH*
  11.     Sorted and added includes
  12.  
  13.     Revision 1.3  1996/08/01 17:41:15  digulla
  14.     Added standard header for all files
  15.  
  16.     Desc:
  17.     Lang: english
  18. */
  19. #include "exec_intern.h"
  20. #include "semaphores.h"
  21.  
  22. /*****************************************************************************
  23.  
  24.     NAME */
  25.     #include <exec/semaphores.h>
  26.     #include <clib/exec_protos.h>
  27.  
  28.     __AROS_LH2(ULONG, Procure,
  29.  
  30. /*  SYNOPSIS */
  31.     __AROS_LHA(struct SignalSemaphore  *, sigSem, A0),
  32.     __AROS_LHA(struct SemaphoreMessage *, bidMsg, A1),
  33.  
  34. /*  LOCATION */
  35.     struct ExecBase *, SysBase, 90, Exec)
  36.  
  37. /*  FUNCTION
  38.     Tries to get a lock on a semaphore in an asynchronous manner.
  39.     If the semaphore is not free this function will not wait but
  40.     just post a request to the semaphore. As soon as the semaphore is
  41.     available the bisMsg will return and make you owner of the semaphore.
  42.  
  43.     INPUTS
  44.     sigSem - pointer to semaphore structure
  45.     bidMsg - pointer to a struct SemaphoreMessage. This should lie in
  46.          public or at least shared memory.
  47.  
  48.     RESULT
  49.     Principly none. Don't know. Just ignore it.
  50.  
  51.     NOTES
  52.     Locks obtained with Procure() must be released with Vacate().
  53.  
  54.     EXAMPLE
  55.  
  56.     BUGS
  57.  
  58.     SEE ALSO
  59.     Vacate()
  60.  
  61.     INTERNALS
  62.  
  63.     HISTORY
  64.     29-10-95    digulla automatically created from
  65.                 exec_lib.fd and clib/exec_protos.h
  66.     22-01-96    fleischer implementation
  67.  
  68. *****************************************************************************/
  69. {
  70.     __AROS_FUNC_INIT
  71.     __AROS_BASE_EXT_DECL(struct ExecBase *,SysBase)
  72.  
  73.     /* Prepare semaphore message to be a sent message */
  74.     bidMsg->ssm_Message.mn_Length=sizeof(struct SemaphoreMessage);
  75.     bidMsg->ssm_Message.mn_Node.ln_Type=NT_MESSAGE;
  76.  
  77.     /* Arbitrate for the semaphore structure */
  78.     Forbid();
  79.  
  80.     /* Try to get the semaphore immediately. */
  81.     if((IPTR)(bidMsg->ssm_Message.mn_Node.ln_Name)==SM_SHARED?
  82.        AttemptSemaphoreShared(sigSem):AttemptSemaphore(sigSem))
  83.     {
  84.     /* Got it. Reply the message. */
  85.     bidMsg->ssm_Semaphore=sigSem;
  86.     ReplyMsg(&bidMsg->ssm_Message);
  87.     }
  88.     else
  89.     /* Couldn't get it. Add message to the semaphore's waiting queue. */
  90.     AddTail((struct List *)&sigSem->ss_WaitQueue,&bidMsg->ssm_Message.mn_Node);
  91.  
  92.     /* All done. */
  93.     Permit();
  94.  
  95.     /* Huh? */
  96.     return 0;
  97.     __AROS_FUNC_EXIT
  98. } /* Procure */
  99.  
  100.